'use strict';
/**
 * @ngdoc function
 * @name sbAdminApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the sbAdminApp
 */
angular.module('sbAdminApp')
    .controller('EsfConfigCtrl', function($scope, $state, esfConfigService) {
    	esfConfigService.pageQuery().then(function(dataResponse) {
            $scope.lists = dataResponse.data['list'];
        });
        $scope.addnew = function() {
        	$("#config_code").val("");
        	$("#config_value").val("");
        	$("#config_confMemo").val(""); 
        };
        $scope.edit = function(dataObj) {
        	$("#config_code").val(dataObj.item.code);
        	$("#config_value").val(dataObj.item.value);
        	$("#config_confMemo").val(dataObj.item.confMemo);            
        };
        $scope.configDel = function(code) {
            if (confirm("确定删除该记录？")) {
            	esfConfigService.configDel(code).then(function(){
            		$state.go("home.service.esfconfig",{}, {reload: true}); 
       			 	$("div[class='modal-backdrop fade in']").hide();        		
            	});
            }
        };
        $scope.configSave = function() {
        	var code = $("#config_code").val();
        	var value = $("#config_value").val();
        	var confMemo = $("#config_confMemo").val();
        	
        	if (trim(code) == "") {
        		alert("配置项不能为空");
        		
        		return;
        	}
        	
        	esfConfigService.configSave(code, value, confMemo).then(function(){
        		$state.go("home.service.esfconfig",{}, {reload: true}); 
   			 	$("div[class='modal-backdrop fade in']").hide();        		
        	});
        }
    });